#include "config.h"
+#define COGL_ENABLE_EXPERIMENTAL_API /* for cogl_framebuffer_allocate */
+
#include "st-texture-cache.h"
#include "st-private.h"
#include <gtk/gtk.h>
G_DEFINE_TYPE(StTextureCache, st_texture_cache, G_TYPE_OBJECT);
/* We want to preserve the aspect ratio by default, also the default
- * material for an empty texture is full opacity white, which we
+ * pipeline for an empty texture is full opacity white, which we
* definitely don't want. Skip that by setting 0 opacity.
*/
static ClutterTexture *
/* Reverse the opacity we added while loading */
static void
-set_texture_cogl_texture (ClutterTexture *clutter_texture, CoglHandle cogl_texture)
+set_texture_cogl_texture (ClutterTexture *clutter_texture, CoglTexture *cogl_texture)
{
clutter_texture_set_cogl_texture (clutter_texture, cogl_texture);
g_object_set (clutter_texture, "opacity", 255, NULL);
G_CALLBACK (on_icon_theme_changed), self);
self->priv->keyed_cache = g_hash_table_new_full (g_str_hash, g_str_equal,
- g_free, cogl_handle_unref);
+ g_free, cogl_object_unref);
self->priv->outstanding_requests = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
self->priv->file_monitors = g_hash_table_new_full (g_str_hash, g_str_equal,
return g_simple_async_result_get_op_res_gpointer (simple);
}
-static CoglHandle
-pixbuf_to_cogl_handle (GdkPixbuf *pixbuf)
+static CoglTexture *
+pixbuf_to_cogl_texture (GdkPixbuf *pixbuf)
{
- return cogl_texture_new_from_data (gdk_pixbuf_get_width (pixbuf),
- gdk_pixbuf_get_height (pixbuf),
- COGL_TEXTURE_NONE,
- gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
- COGL_PIXEL_FORMAT_ANY,
- gdk_pixbuf_get_rowstride (pixbuf),
- gdk_pixbuf_get_pixels (pixbuf));
+ ClutterBackend *backend = clutter_get_default_backend ();
+ CoglContext *ctx = clutter_backend_get_cogl_context (backend);
+
+ return COGL_TEXTURE (cogl_texture_2d_new_from_data (ctx,
+ gdk_pixbuf_get_width (pixbuf),
+ gdk_pixbuf_get_height (pixbuf),
+ gdk_pixbuf_get_has_alpha (pixbuf) ? COGL_PIXEL_FORMAT_RGBA_8888 : COGL_PIXEL_FORMAT_RGB_888,
+ gdk_pixbuf_get_rowstride (pixbuf),
+ gdk_pixbuf_get_pixels (pixbuf),
+ NULL));
}
static cairo_surface_t *
{
GSList *iter;
StTextureCache *cache;
- CoglHandle texdata = NULL;
+ CoglTexture *texdata = NULL;
cache = data->cache;
if (pixbuf == NULL)
goto out;
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_texture (pixbuf);
if (data->policy != ST_TEXTURE_CACHE_POLICY_NONE)
{
if (!g_hash_table_lookup_extended (cache->priv->keyed_cache, data->key,
&orig_key, &value))
{
- cogl_handle_ref (texdata);
+ cogl_object_ref (texdata);
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (data->key),
texdata);
}
out:
if (texdata)
- cogl_handle_unref (texdata);
+ cogl_object_unref (texdata);
texture_load_data_free (data);
}
const char *propname)
{
GdkPixbuf *pixbuf;
- CoglHandle texdata;
+ CoglTexture *texdata;
g_object_get (bind->source, propname, &pixbuf, NULL);
if (pixbuf != NULL)
{
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_texture (pixbuf);
g_object_unref (pixbuf);
clutter_texture_set_cogl_texture (bind->texture, texdata);
- cogl_handle_unref (texdata);
+ cogl_object_unref (texdata);
clutter_actor_set_opacity (CLUTTER_ACTOR (bind->texture), 255);
}
*
* Create a #ClutterTexture which tracks the #GdkPixbuf value of a GObject property
* named by @property_name. Unlike other methods in StTextureCache, the underlying
- * CoglHandle is not shared by default with other invocations to this method.
+ * #CoglTexture is not shared by default with other invocations to this method.
*
* If the source object is destroyed, the texture will continue to show the last
* value of the property.
*
* Returns: (transfer full): A newly-referenced handle to the texture
*/
-CoglHandle
+CoglTexture *
st_texture_cache_load (StTextureCache *cache,
const char *key,
StTextureCachePolicy policy,
void *data,
GError **error)
{
- CoglHandle texture;
+ CoglTexture *texture;
texture = g_hash_table_lookup (cache->priv->keyed_cache, key);
if (!texture)
if (texture)
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texture);
else
- return COGL_INVALID_HANDLE;
+ return NULL;
}
- cogl_handle_ref (texture);
+
+ cogl_object_ref (texture);
return texture;
}
AsyncTextureLoadData **request,
ClutterActor *texture)
{
- CoglHandle texdata;
+ CoglTexture *texdata;
AsyncTextureLoadData *pending;
gboolean had_pending;
load_from_pixbuf (GdkPixbuf *pixbuf)
{
ClutterTexture *texture;
- CoglHandle texdata;
+ CoglTexture *texdata;
int width = gdk_pixbuf_get_width (pixbuf);
int height = gdk_pixbuf_get_height (pixbuf);
clutter_actor_set_size (CLUTTER_ACTOR (texture), width, height);
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_texture (pixbuf);
set_texture_cogl_texture (texture, texdata);
- cogl_handle_unref (texdata);
+ cogl_object_unref (texdata);
return CLUTTER_ACTOR (texture);
}
return CLUTTER_ACTOR (texture);
}
-static CoglHandle
+static CoglTexture *
st_texture_cache_load_uri_sync_to_cogl_texture (StTextureCache *cache,
StTextureCachePolicy policy,
const gchar *uri,
int scale,
GError **error)
{
- CoglHandle texdata;
+ CoglTexture *texdata;
GdkPixbuf *pixbuf;
char *key;
if (!pixbuf)
goto out;
- texdata = pixbuf_to_cogl_handle (pixbuf);
+ texdata = pixbuf_to_cogl_texture (pixbuf);
g_object_unref (pixbuf);
if (policy == ST_TEXTURE_CACHE_POLICY_FOREVER)
{
- cogl_handle_ref (texdata);
+ cogl_object_ref (texdata);
g_hash_table_insert (cache->priv->keyed_cache, g_strdup (key), texdata);
}
}
else
- cogl_handle_ref (texdata);
+ cogl_object_ref (texdata);
ensure_monitor_for_uri (cache, uri);
}
/**
- * st_texture_cache_load_file_to_cogl_texture:
+ * st_texture_cache_load_file_to_cogl_texture: (skip)
* @cache: A #StTextureCache
* @file_path: Path to a file in supported image format
* @scale: Scale factor of the display
*
* This function synchronously loads the given file path
* into a COGL texture. On error, a warning is emitted
- * and %COGL_INVALID_HANDLE is returned.
+ * and %NULL is returned.
*
- * Returns: (transfer full): a new #CoglHandle
+ * Returns: (transfer full): a new #CoglTexture
*/
-CoglHandle
+CoglTexture *
st_texture_cache_load_file_to_cogl_texture (StTextureCache *cache,
const gchar *file_path,
gint scale)
{
- CoglHandle texture;
+ CoglTexture *texture;
GFile *file;
char *uri;
GError *error = NULL;
{
g_warning ("Failed to load %s: %s", file_path, error->message);
g_clear_error (&error);
- return COGL_INVALID_HANDLE;
+ return NULL;
}
return texture;
}